package com.tender.controller;

import com.tender.events.OrderEvent;
import com.tender.service.BizOrderStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ApproveController {

    @Autowired
    private BizOrderStatusService orderStatusService;

    /**
     * 前端调用start方法将订单状态改为审核中，并自动持久化到数据库
     * @param orderId  订单id  eg: 1892816917354635272
     * @return
     */
    @GetMapping("/start/{orderId}")
    public void start(@PathVariable("orderId") Long orderId) {
        orderStatusService.eventHandler(orderId, OrderEvent.APPROVE_START);
    }

    /**
     * 前端调用start方法将订单状态改为审核成功，并自动持久化到数据库
     * @param orderId  订单id
     * @return
     */
    @GetMapping("/approveSuccess/{orderId}")
    public void approveSuccess(@PathVariable("orderId") Long orderId) {
        orderStatusService.eventHandler(orderId,OrderEvent.APPROVE_SUCCESS);
    }

    /**
     * 前端调用start方法将订单状态改为审核失败，并自动持久化到数据库
     * @param orderId  订单id
     * @return
     */
    @GetMapping("/approveFailed/{orderId}")
    public void approveFailed(@PathVariable("orderId") Long orderId) {
        orderStatusService.eventHandler(orderId,OrderEvent.APPROVE_FAILED);
    }

}
